package com.tyjc.unique.bean;

import com.fyzk.utils.LotteryIDUtils;

import org.json.JSONException;
import org.json.JSONObject;

public class SSQTrendChart {

	private int id;

	private int lotteryType;

	private String phase;

	private String value;

	private String wincode;

	public void setId(int id) {
		this.id = id;
	}

	public int getId() {
		return this.id;
	}

	public void setLotteryType(int lotteryType) {
		this.lotteryType = lotteryType;
	}

	public int getLotteryType() {
		return this.lotteryType;
	}

	public void setPhase(String phase) {
		this.phase = phase;
	}

	public String getPhase() {
		return this.phase;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public String getValue() {
		return this.value;
	}

	public void setWincode(String wincode) {
		this.wincode = wincode;
	}

	public String getWincode() {
		return this.wincode;
	}

	public String[] hongMiss() {
		String[] missNum = null;
		try {
			JSONObject  obj = new JSONObject(value);
			JSONObject hongM = obj.getJSONObject("ssq");
			String red = hongM.getString("red");
			red =  red.subSequence(1, red.length()-1).toString();
			missNum = red.split(",");
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return missNum;
	}

	public String[] lanMiss() {
		String[] missNum = null; 
		try {
			JSONObject  obj = new JSONObject(value);
			JSONObject hongM = obj.getJSONObject("ssq");
			String red = hongM.getString("blue");
			red.subSequence(1, red.length()-1);
			red =  red.subSequence(1, red.length()-1).toString();
			missNum = red.split(",");
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return missNum;
	}

	public String[] missValue() {
		String[] missNum = null;
		String missValue = "";
		try {
			JSONObject  obj = new JSONObject(value);
			JSONObject hongM = obj.getJSONObject(getObjTitle());
			String[] itemTitles = getItemTitles();
			for (int i = 0; i < itemTitles.length; i++) {
				if (hongM.has(itemTitles[i])) {
					String red = hongM.getString(itemTitles[i]);
					red =  red.subSequence(1, red.length()-1).toString();
					missValue += red + ",";
				}
			}
			missValue = missValue.substring(0,missValue.length()-1);
			missNum = missValue.split(",");

		} catch (JSONException e) {
			e.printStackTrace();
		}
		return missNum;
	}

	private String getObjTitle() {
		switch (lotteryType) {
			case LotteryIDUtils.SSQ_LOTTERY_ID_INT:
				return "ssq";
			case LotteryIDUtils.DLT_LOTTERY_ID_INT:
				return "dlt";
			case LotteryIDUtils.FC3D_LOTTERY_ID_INT:
				return "pttz";
			case LotteryIDUtils.PL3_LOTTERY_ID_INT:
				return "zx";
			case LotteryIDUtils.PL5_LOTTERY_ID_INT:
				return "plw";
			case LotteryIDUtils.QXC_LOTTERY_ID_INT:
				return "qxc";
			default:
				return "ssq";
		}
	}

	private String[] getItemTitles() {
		switch (lotteryType) {
			case LotteryIDUtils.SSQ_LOTTERY_ID_INT:
				return new String[]{"red","blue"};
			case LotteryIDUtils.DLT_LOTTERY_ID_INT:
				return new String[]{"qian","hou"};
			case LotteryIDUtils.FC3D_LOTTERY_ID_INT:
			case LotteryIDUtils.PL3_LOTTERY_ID_INT:
				return new String[]{"bai","shi", "ge"};
			case LotteryIDUtils.PL5_LOTTERY_ID_INT:
				return new String[]{"wan","qian","bai","shi", "ge"};
			case LotteryIDUtils.QXC_LOTTERY_ID_INT:
				return new String[]{"baiwan","shiwan","wan","qian","bai","shi", "ge"};
			default:
				return new String[]{"red","blue"};
		}
	}


}
